#include "stm32f10x.h"
#include <stdint.h>
#include "TinyOS_Task.h"
#include "TinyOS_Switch.h"
#include "TinyOS_Delay.h"
#include "TinyOS_Config.h"
#include "TinyOS_CpuTicks.h"
#include "TinyOS_Event.h"
#include "TinyOS_Semaphore.h"
#include "TinyOS_MailBox.h"
#include "TinyOS_MemBlock.h"
#include "TinyOS_FlagGroup.h"
#include "TinyOs_Mutex.h"
#include "TinyOS_Timer.h"
#include "app.h"

float CpuUsageCount = 0.0F;

uint8_t Task1Flag;
uint8_t Task2Flag;
uint8_t Task3Flag;
uint8_t Task4Flag;

TinyOS_TaskType         Task1Handler;
TinyOS_TaskType         Task2Handler;
TinyOS_TaskType         Task3Handler;
TinyOS_TaskType         Task4Handler;

TinyOS_TaskStackType    Task1Stack[512];
TinyOS_TaskStackType    Task2Stack[512];
TinyOS_TaskStackType    Task3Stack[512];
TinyOS_TaskStackType    Task4Stack[512];

void Task1Func(void *param);
void Task2Func(void *param);
void Task3Func(void *param);
void Task4Func(void *param);


void Task1Func(void *param)
{      
    

   
    for(;;)
    {                
		Task1Flag = 0;
        TinyOS_TaskDelay(TINYOS_TICKS_PER_SECOND);
		Task1Flag = 1;
        TinyOS_TaskDelay(TINYOS_TICKS_PER_SECOND);        

    }
}

void Task2Func(void *param)
{
    for(;;)
    {            
		Task2Flag = 0;
        TinyOS_TaskDelay(1);
		Task2Flag = 1;
        TinyOS_TaskDelay(1);   
	
    }
}

void Task3Func(void *param)
{
    for(;;)
    {    
		Task3Flag = 0;
		TinyOS_TaskDelay(1);
		Task3Flag = 1;
		TinyOS_TaskDelay(1);

    }
}

void Task4Func(void *param)
{   
    for(;;)
    {     
		Task4Flag = 0;
		TinyOS_TaskDelay(1);
		Task4Flag = 1;
		TinyOS_TaskDelay(1);
		
    }
}

void AppTaskInit(void)
{
    TinyOS_TaskInit(
        &Task1Handler, 
        Task1Func, 
        (void*)0x11111111, 
         0, 
        Task1Stack,
		sizeof(Task1Stack)
    );
    TinyOS_TaskInit(
        &Task2Handler, 
        Task2Func, 
        (void*)0x22222222, 
        1, 
        Task2Stack,
		sizeof(Task2Stack)
    );
    TinyOS_TaskInit(
        &Task3Handler, 
        Task3Func, 
        (void*)0x33333333, 
        1, 
        Task3Stack,
		sizeof(Task3Stack)
    );
    TinyOS_TaskInit(
        &Task4Handler, 
        Task4Func, 
        (void*)0x44444444, 
        1, 
        Task4Stack,
		sizeof(Task4Stack)
    );
}


